package com.aaa.order.controller;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.entity.Order;
import com.aaa.entity.Product;
import com.aaa.order.openfeign.ProductOpenFeign;
import com.aaa.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author ：ludi（206913808@qq.com）
 * @date ：Created in 2022/11/17 17:08
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("order")
@SuppressWarnings({"all"})
public class OrderControllerByFegin {


    @Autowired
    private ProductOpenFeign productOpenFeign;

    @Autowired
    private OrderService orderService;


    /**
     * @param pid
     * @param
     * @return com.aaa.entity.Result
     * @create by: ludi（206913808@qq.com）
     * @description: 提交订单
     * @create time: 2022/11/17 17:21
     */
    @GetMapping("/saveOrder")
    public String saveOrder(Long pid, Integer num) {
        Order order = new Order();

        order.setUid(1);
        order.setUsername("逯迪");
        order.setPid(pid);

        Product product = productOpenFeign.selectById(pid);

        if (ObjectUtil.isNotEmpty(product)) {
            order.setPname(product.getPname());
            order.setPprice(product.getPprice());
            order.setNumber(num);
            orderService.save(order);
            return "下单成功le";
        }else {
            return "下单失败";
        }
    }


}